<%
   # Quick check of project and repo URLs.  This check is for responsiveness,
   # not for security; they're checked more rigorously
   # at the server (see app/validators/url_validator.rb).
   # This pattern is intentionally limited, e.g., we don't allow '?', to make
   # it harder to use this app to attack improperly-written sites.
   # The regex syntax here is per the *HTML* spec for HTML5 patterns, so
   # "^" and "$" are not needed.
   domain_pattern = '[A-Za-z0-9_][-A-Za-z0-9_.]*'
   url_pattern = 'https?:\/\/' + domain_pattern + \
     '(\/([-A-Za-z0-9_.:\/\+!,#@~]|%(20|[89A-Ea-e][0-9A-Fa-f]|[Ff][0-7]))*)?'
%>
<% if logged_in? %>
  <div class='row'>
  <div class="col-md-12">
  <br>
  <h2 class='center'><%= t('.new_badge') %></h2>
  <br>
  <%= raw t('.tell_us') %>
  <br>
  <% if current_user.provider == 'github'%>
     <h4><%= t '.may_select_html' %></h4>
     <br>
     <!-- For convenience we provide a list of GitHub repos (sorted by
          the datetime of their most recent push).  We limit the length
          of this list to prevent a timeout.  -->
     <%= form_for(@project) do |f| %>
       <%= render 'shared/error_messages', object: f.object %>
       <%= f.collection_select :repo_url, github_select, :last, :first,
                               { prompt: t('.select_one_github'),
                                 disabled: lambda{ |repo| repo.last == 'none' }}
       %>
       <%= f.submit t('.submit_github'), class: 'btn btn-primary',
                    'data-toggle' => 'tooltip',
                    title: t('.post_delay_warning') %>
     <% end %>

     <br><h2 class='center'><%= t('.new_badge_or') %></h2>
  <% end %>
  <br>
  <%= form_for(@project) do |f| %>
      <% if current_user.provider == 'local'%>
        <%= render 'shared/error_messages', object: f.object %>
      <% end %>
      <span><%= f.label :homepage_url, t('.url_of_homepage') %></span>
      <!-- Note: Server tests URLs, this is just sanity checking -->
      <%= f.text_field :homepage_url, class:"form-control",
            type: 'url', skip_label: true,
            pattern: url_pattern,
            placeholder: t('.placeholder_of_homepage') %>
      <span><%= f.label :repo_url, t('.url_of_repo') %></span>
      <%= f.text_field :repo_url, class:"form-control",
            type: 'url', skip_label: true,
            pattern: url_pattern,
            placeholder: t('.placeholder_of_repo') %>
     <%= f.submit t('.submit_urls'), class: 'btn btn-primary',
                  'data-toggle' => 'tooltip', title: t('.post_delay_warning') %>
  <% end %>
  <p>
  <br><br>
  <%= t('.final_text_html') %>
  </div>
  </div>
<% else %>
  <% flash.now[:danger] = t('.sign_in_first') %>
  <%= render template: 'sessions/new' %>
<% end %>
